﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using Village_Project.Core;
namespace Village_Project
{
    public partial class CarerSelect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string fCIDstring = Request.QueryString["fCID"];
            string CIDstring = Request.QueryString["CID"];


            if (CIDstring != null && fCIDstring != null)
            {
                insertcarer();
            }

            else
            {
            }

        }
        protected void insertcarer()
        {
            string fCIDstring = Request.QueryString["fCID"];
            string CIDstring = Request.QueryString["CID"];


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            //deletecarer();
            SqlCommand CmdSql2 = new SqlCommand("UPDATE [Family] SET CarerStatus='1' where CID=@CID and FMemberCID=@fCID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", CIDstring);
            CmdSql2.Parameters.AddWithValue("@fCID", fCIDstring);

            CmdSql2.ExecuteNonQuery();

            conn.Close();

            MessageBoxurl("เลือกผู้ดูแลหลักเรียบร้อยครับ", "regfamily.aspx");



        }

        public void deletecarer()
        {

            string fCIDstring = Request.QueryString["fCID"];
            string CIDstring = Request.QueryString["CID"];
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql = new SqlCommand("delete from [Carer] where CID=@CID and fCID=@fCID", conn);
            conn.Open();
            CmdSql.Parameters.AddWithValue("@CID", CIDstring);
            CmdSql.Parameters.AddWithValue("@fCID", fCIDstring);
            CmdSql.ExecuteNonQuery();

            conn.Close();
        }

        private void MessageBoxurl(string msg, string urld)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');" + "window.location.href='" + urld + "';" + "</script>";
            Page.Controls.Add(lbl);
        }

    }
}
 